<template>
  <div class="reg">
    <div v-if="index0">
      <div class="reg_title f52 col_33">登录</div>
      <div class="f32 col_66">还没有账号,<span class="to_reg" @click="$router.push('/reg')">立即注册</span></div>
      <div class="reg_list_box">
        <div class="reg_list">
          <input class="list_write_input f32" v-model="userTel" type="text" placeholder="请输入手机号" maxlength="11">
        </div>
        <div class="reg_list reg_list_ma">
          <input class="list_ma_input f32" v-model="userPass" type="password" placeholder="请输入密码">
          <button class="ma_btn f32 col_33" @click="$router.push('/forget')">忘记密码</button>
        </div>
      </div>
      <div class="global_btn reg_btn" @click="regBtn">登录</div>
    </div>
    <img v-if="index1" @click="changehide1" class="index_image index1" src="@/common/image/index1.jpg" alt="">
  </div>
</template>
<script>
// import {mapActions} from 'vuex'
export default {
  name: '',
  components: {},
  data() {
    return {
      userTel: '', // 手机号
      userPass: '', // 密码
      index0: false,
      index1: true
    }
  },
  mounted() {},
  methods: {
    changehide1(){
      this.index1 = false
      this.index0 = true
    },
    // ...mapActions('home',['updateUser']),
    regBtn(){
      var $this = this;
      // 验证手机号
     if ($this.userTel.length != 11) {
        this.$toast({
          message: '请输入正确的手机号',
          duration: 800
        });
       return;
      }else if (!/^[\w]{6,12}$/.test($this.userPass)){
        this.$toast({
          message: '请输入6到12位密码',
          duration: 800
        });
       return;
      }else{
       var data = {phone: $this.userTel,pass:$this.userPass};
       $this.$axios.post('index.php?m=index&c=login',data)
         .then((res) => {
           // $this.updateUser(Object.assign({}, {id:res.data.user.id,},));
           // $this.updateUser(res.data.user);
           if(res.data.code == 1){
            $this.$toast({
              message: res.data.msg,
              duration: 800,
              onClose:()=>{
                $this.$router.push("/");
              }
            })
            localStorage.setItem('uid',res.data.user.id);
            localStorage.setItem('token',res.data.token);
            localStorage.setItem('isVip',res.data.user.m_level);
            if(res.data.user.m_rz == 0){
              localStorage.setItem('isRenzheng',0);
            } else {
              localStorage.setItem('isRenzheng',1);
            }
           }else{
             $this.$toast({
               message: res.data.msg,
               duration: 800
             })
           }
         })
     }
    }
  },
}
</script>
<style lang="less">
  .reg{
    padding: 0.8rem;
    .reg_title{ margin-top: 0.4888rem; margin-bottom: 0.2rem; }
    .to_reg{ color: #409aff; }
    .reg_list_box{
      margin-top: 1.2rem;
      .reg_list{
        height: 1.3333rem;
        border-bottom: 1Px solid rgba(0, 0, 0, 0.05);
        margin-bottom: 0.4rem;
        .list_write_input{
          height: 100%;
          width: 100%;
        }
      }
      .reg_list_ma{
        display: flex;
        display: -webkit-flex;
        justify-content: space-between;
        -webkit-justify-content: space-between;
        .ma_btn{
          background: #fff;
        }
      }
    }
    .reg_btn{ margin-top: 1.5rem; }
    .index_image{
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
    .index1{ z-index: 10; }
    .index2{ z-index: 13; }
  }

</style>
